package com.autonavi.collapse.concurrent;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

public class IdentifyThreadFactory implements ThreadFactory {

    private String name;

    private AtomicInteger index = new AtomicInteger();

    public IdentifyThreadFactory(String name){
        this.name = name;
    }

    @Override
    public Thread newThread(Runnable r) {
        String threadName = name + "-" + index.getAndIncrement();
        Thread thread = new Thread(r);
        thread.setName(threadName);
        return thread;
    }
}
